package com.ciwong.epaper.common.guidedialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
/**
 * date :2018/6/27
 * author: lzh
 * description: 引导层基类（可以统一处理各种样式及背景）
 * version:
 */

public class BaseGuideLayerDialog extends Dialog {

    private Window window;
    private WindowManager.LayoutParams lp;

    public BaseGuideLayerDialog(@NonNull Context context) {
        this(context,-1);
    }

    public BaseGuideLayerDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        removePadding();
    }

    protected BaseGuideLayerDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        removePadding();
}

    private void removePadding() {
        window = getWindow();
//        window.setBackgroundDrawableResource(R.color.color_cc323533);
    }

    @Override
    public void setContentView(@NonNull View view) {
        super.setContentView(view);
        setUnifyWindow(window);
    } @Override
    public void setContentView(@NonNull int  res) {
        super.setContentView(res);
        setUnifyWindow(window);
    }

    private void setUnifyWindow( Window window) {
        lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
//        lp.gravity = Gravity.CENTER;
        window.setAttributes(lp);
    }
}
